package com.relytosoft.mizar.media.common.utils;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.relytosoft.dubhe.common.core.exception.ServiceException;
import com.relytosoft.dubhe.common.core.object.ResponseResult;

/**
 * 转码
 *
 * @Author SunLi
 * @Date: 2022/4/15 11:29
 * @Version 1.0
 */
public class TransRequestUtil {
    public static String handlerResponse(String result) {
        if (StrUtil.isEmpty(result)) {
            throw new ServiceException("转码接口返回的结果错误");
        }
        try {
            ResponseResult responseResult = JSON.parseObject(result, ResponseResult.class);
            if (responseResult.getCode() != 0) {
                throw new ServiceException("转码接口返回的结果错误:" + responseResult.getMsg());
            }
            if(StrUtil.isBlankIfStr(responseResult.getData())){
                return "";
            }
            return responseResult.getData().toString();
        } catch (Exception ex) {
            throw new ServiceException(ex.getMessage());
        }
    }
}
